// import gcoord from "../../miniprogram_npm/gcoord/dist/gcoord";
var utils = require("../utils/apis");
const dayjs = require("dayjs");

Page({
  /**
   * 页面的初始数据
   */
  data: {
    originList: [],
    selectValue: 1,
    loading: true,
    pageNum: 1,
    total: '',
    size: 10,
    serach_pro: '',
    startDateIsshow: false,
    startDate: '开始日期',
    endDate: '结束日期',
    minDate: new Date(2020, 1, 1).getTime(),
    maxDate: new Date().getTime(),
    defaultTime: [],
    timer: ''
  },
  // selectTab (e) {
  //   this.setData({
  //     selectValue: e.detail.title === "定向需求" ? 1 : 0,
  //     originList: [],
  //     pageNum: 1,
  //   });
  //   this.setData({
  //     timer: Date.parse(new Date())
  //   })
  //   this.getInfos(this.data.timer);
  // },
  goScreening () {
    this.setData({
      isUpdate: false
    })
    const content = JSON.stringify(this.data.selectedObj)
    wx.navigateTo({
      url: `/sub_jinfu/screening/screening?content=${content}`,
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad (options) {
    this.setData({
      timer: Date.parse(new Date())
    })
    this.getInfos(this.data.timer);
  },

  goSearch () {
    this.setData({
      pageNum: 1,
      originList: [],
    })
    this.setData({
      timer: Date.parse(new Date())
    })
    this.getInfos(this.data.timer);
  },

  // 初始化数据
  async getInfos (timer) {
    this.setData({
      loading: true
    })
    wx.showLoading({
      title: "加载中",
    });
    // 全量的条件
    const params = {
      startTime: this.data.startDate === '开始日期' ? '' : this.data.startDate,
      endTime: this.data.endDate === '结束日期' ? '' : this.data.endDate,
      current: this.data.pageNum,
      size: this.data.size,
      keyword: this.data.serach_pro || ''
    };
    const finalParams = { ...params }
    console.log(finalParams, "finalParams");
    const res = await utils.apis(
      "/api/finance/corReqMakeLoan/creditList",
      finalParams,
      "GET",
      true
    );
    if (this.data.timer == timer) {
      wx.hideLoading();
      console.log(res, "金服列表信息res");
      this.setData({
        originList: this.data.originList.concat(res.data.records),
        total: res.data.total,
        loading: false,
      });
    }
  },

  toDetail (e) {
    wx.navigateTo({
      url: `/sub_jinfu/list3_detail/list3_detail?id=${e.currentTarget.dataset.id}&creditId=${e.currentTarget.dataset.id1}`,
    })
  },

  goOnChange (e) {
    // console.log(e, '1323213213')
    this.setData({
      serach_pro: e.detail,
    });
  },
  clearTimer () {
    this.setData({
      startDate: '开始日期',
      endDate: '结束日期',
    })
    this.goSearch()
  },
  startDateCancel () {
    this.setData({
      startDateIsshow: false,
      endDateIsshow: false,
    })
  },
  startDateclick () {
    this.setData({
      startDateIsshow: true,
    })
  },
  startDateConfirm (e) {
    // console.log(dayjs(new Date(e.detail[0])).format("YYYY-MM-DD"));
    this.setData({
      startDate: dayjs(new Date(e.detail[0])).format("YYYY-MM-DD"),
      endDate: dayjs(new Date(e.detail[1])).format("YYYY-MM-DD"),
      startDateIsshow: false
    })
    this.goSearch()
  },

  scrollBottom () {
    if (this.data.pageNum * this.data.size < this.data.total) {
      this.setData({
        timer: Date.parse(new Date())
      })
      this.setData({
        pageNum: ++this.data.pageNum,
      });
      this.getInfos(this.data.timer);
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady () { },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow () {
    // console.log(this.data.isUpdate, 'this.data.isUpdate')
    // if (this.data.isUpdate) {
    //   this.setData({
    //     pageNum: 1,
    //     originList: [],
    //   })
    //   this.setData({
    //     timer: Date.parse(new Date())
    //   })
    //   this.getInfos(this.data.timer);
    // }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide () { },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload () { },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh () { },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage () { },
});
